import api from '@/api'
//import storage from '../../utils/storage'
const car ={
    namespaced: true,
    state:{
        carList:[]
    },
    getters:{
        count(state){
            let num=0
            state.carList.forEach(item=>{
                if(item.active==='1'){
                    num+=item.num
                }
            })
            return num
        }
    },
    mutations:{
        SET_CAR_LIST(state,payload){
            state.carList=payload
        }
    },
    actions:{
       async getCarList({commit}){
           const res =await api.car.list()
           commit('SET_CAR_LIST',res.data)
       },
       async add({dispatch},payload){
         await api.car.add(payload)
           dispatch('getCarList')
       },
       async update({dispatch},payload){
           await api.car.update(payload)
           dispatch('getCarList')
       }
    },
    modules:{
        
    }
}
export default{
    car
}
